<?php

namespace App\Http\Requests\Admin;
use App\Http\Requests\FormRequest;

/**
 * @Author: dxf
 * @Date: 2021-07-16
 * @Time: 16:00
 */

/**
 * 后台认证
 */
class AdminAuthRequest extends FormRequest
{

    public function rules()
    {
        switch ($this->method()) {
            case 'GET':
            case 'POST':
            {
                return [
                    'login_type'     => ['required', 'in:account,phone,wechat'],
                    'account'        => ['required_if:login_type,account', 'string', 'between:2,20'],
                    'phone'          => ['required_if:login_type,phone', 'regex:/^1[123456789][0-9]{9}$/'],
                    'wechat_unionid' => ['required_if:login_type,wechat', 'string'],
                    'password'       => ['required_if:login_type,account,phone', 'between:5,20'],
                ];
            }
            case 'PUT':
            case 'PATCH':
            case 'DELETE':
            default:
            {
                return [

                ];
            }
        }
    }

    public function messages()
    {
        return [
            'login_type.required'           => '登录方式必须',
            'login_type.in'                 => '登录方式错误',
            'account.required_if'           => '账号必填',
            'account.regex'                 => '账号必须在:min和:max之间',
            'phone.required_if'             => '手机号必填',
            'phone.regex'                   => '手机号不符合规范',
            'wechat_unionid.required_if'    => '微信账号必填',
            'wechat_unionid.string'         => '微信账号不符合规范',
            'password.between'              => '密码必须在:min和:max之间',
            'password.required_if'          => '密码必填',
            'transaction_password.required' => '交易密码必填',
            'transaction_password.size'     => '交易密码必须是:size位字符',
            'openid.required'               => 'openid必须',
            'nickname.required'             => '昵称必须',
            'avatar.required'               => '头像必须',
        ];
    }
}
